$(document).ready(function() {
	
	$("#selectall").click(function() {
        if ($("#selectall").prop("checked") == true) {
            $(".chek_all").prop("checked", true);
        } else {
            $(".chek_all").prop("checked", false);
        }
    });
	
     var switches = document.querySelectorAll('input[type="checkbox"].ios-switch');
    for (var i = 0, sw; sw = switches[i++]; ) {
        var div = document.createElement('div');
        div.className = 'switch-div';
        sw.parentNode.insertBefore(div, sw.nextSibling);
    }
        
      $(".manage_alert_chkbox").click(function(){
        var checked_alert = $(this).is(":checked");
        var alert_id = $(this).attr('alert_id');
        var postdata = {};
        postdata['checked_alert'] = checked_alert;
        postdata['alert_id'] = alert_id;
        postdata['status'] = 'managestatus';
            jQuery.post(BASE_PATH + '/member/alertupdate', postdata, function(result) {
                
            });
   });
   
   $(".ma_receive_update").change(function(){
        var ma_receive_update = $(this).val();
        var alert_id = $(this).attr('alert_id');
        var postdata = {};
        postdata['ma_receive_update'] = ma_receive_update;
        postdata['alert_id'] = alert_id;
        postdata['status'] = 'ma_receive_update';
            jQuery.post(BASE_PATH + '/member/alertupdate', postdata, function(result) {
                
            });
   });
   
   $(".ma_next_time").change(function(){
        var ma_next_time = $(this).val();
        var alert_id = $(this).attr('alert_id');
        var postdata = {};
        postdata['ma_next_time'] = ma_next_time;
        postdata['alert_id'] = alert_id;
        postdata['status'] = 'ma_next_time';
            jQuery.post(BASE_PATH + '/member/alertupdate', postdata, function(result) {
                
            });
   });

        
    
    
    // auto complete
    $("#client_referral_name").select2();
    $("#member_id").select2({
       placeholder: "Select Member"
    });
    $("#client_status").select2();
    $("#client_type").select2();
    
    $("#member_id").change(function(){
        var member_id = $(this).val();
        window.location = SITE_URL + 'Member/view/member_id/'+member_id;
    })
    
    //Logic for toggle

  
     
    
 $( "body" ).delegate( ".item-class", "click", function() {
 
 //$('.item-class').click( function(){
    if ($(this).hasClass('item-open') ) {
      var id = $(this).attr('href');
      $(id).hide('slow');
      $(this).removeClass('item-open');
      $(this).addClass('collapsed');
      return false;
    }
    $('.item-class').addClass('collapsed');

    $('.item-class').removeClass('item-open');
    $(this).addClass('item-open');

    $('.item-container').hide('slow');
    var id = $(this).attr('href');

    $(this).removeClass('collapsed');

    $(id).show('slow');
    return false;
 });
 
 
 
 
 
 $(".wysihtml5-editor").each(function() {
        $(this).wysihtml5({
            "font-styles": true, //Font styling, e.g. h1, h2, etc. Default true
            "emphasis": true, //Italics, bold, etc. Default true
            "lists": true, //(Un)ordered lists, e.g. Bullets, Numbers. Default true
            "html": false, //Button which allows you to edit the generated HTML. Default false
            "link": false, //Button to insert a link. Default true
            "image": false, //Button to insert an image. Default true,
            "color": false//Button to change color of font  
        });
    });
    
    
    
//Drag n Drop up-loader for DOCUMENT
    Dropzone.autoDiscover = false;
    //Drag n Drop up-loader for EXTRA_IMAGE
    var paramsdata = {};
    paramsdata['UNIQUEIDENTIFIER'] = UNIQUEIDENTIFIER;
    
    
    $(".document_dropzone").dropzone(
            {
                url: BASE_PATH + '/member/upload',
                paramName: 'DOCUMENT',
                params: paramsdata,
                maxFilesize: 500,
               // acceptedFiles: ".ppt,.pptx,.xls,.xlsx,.odp,.doc,.docx,.pdf,.ppsx",
            }
    );
     
      $('.member-country').change(function() {
          
        var postdata = {};
        var country_id = $(this).val();
        if (country_id === '') {
        } else {
            postdata['country_id'] = country_id;
            jQuery.post(BASE_PATH + '/member/getcitylist', postdata, function(result) {
                $('.member-city').html(result);
            });
        }

    });
    
    $('.mem_client_type').click(function(){
         //var client_type = $(this).val();
         //alert($("#user_type_"+client_type).is(':checked'));
         
         if($("#user_type_buyer").is(':checked')== false && $("#user_type_tenant").is(':checked') == false ){
            // $('.client_datepicker').hide();
             //$('.client_note').hide();
             $("#mem_client_status").val('');
         }
         
         /*if($("#user_type_buyer").is(':checked') || $("#user_type_tenant").is(':checked') ){
            $('.client_status').removeClass('display-none'); 
            
            $('.client_status').show();
         }else{
             $('.client_status').hide();
         }*/
         
    });
    
    
    $('.member-client-status').change(function(){
       
         var client_status = $(this).val();
        
         //if(client_status == 'pending' || client_status == 'incubated'){
            //$('.client_datepicker').removeClass('display-none'); 
            $('.client_datepicker').show();
           // $('.client_note').removeClass('display-none'); 
            $('.client_note').show();
         //}
         /*else{
             $('.client_datepicker').hide();
             $('.client_note').hide();
         }*/
    });
    
    //show client datepicker and note 
    if($("#show_client_datepicker").val() == 1 ){
            //$('.client_datepicker').removeClass('display-none'); 
            $('.client_datepicker').show();
           // $('.client_note').removeClass('display-none'); 
            $('.client_note').show();
    }
    
    
    if($("#show_client_status").val() == 1 ){
         $('.client_status').removeClass('display-none'); 
         $('.client_status').show();
    }
	
     
    
    $('#mem_bday').datepicker({
            format: "dd/mm/yyyy",
            startView: 1,
            autoclose: true,
            todayHighlight: true
    });
    
     $('#mem_client_calender').datepicker({
	    format: "dd/mm/yyyy",
            startDate: "1d",
            autoclose: true,
            todayHighlight: true
     });
	 
	 $('.clockpicker ').clockpicker({
        autoclose: true
    });
    
	$(".chk_all").click(function() {
        //alert($(this).is(":checked"));
        if ($(this).is(":checked") === true) {
            $('.chk_cls').prop('checked', true);
        } else {
            $('.chk_cls').prop('checked', false);
        }
    });
	
    $("#delete_all_assign").click(function(){
        var chkArray = [];
        $(".chek_all:checked").each(function() {
            chkArray.push($(this).val());
        });
        var selected_property;
        selected_property = chkArray.join(',');
        var member_id = $("#current_member_id").val();
        
        var postdata = {};
        var obj = $(this);
        postdata['selected_property'] = selected_property;
        postdata['member_id'] = member_id;
        //$("#ac_property_id").val(selected);
        if (chkArray.length != 0) {
           jQuery.post(BASE_PATH + '/member/deleteassign', postdata, function(result) {
           if(result == 1){
            $("#err_delete").show();
            $("#err_delete").html('Property deleted successfully');
                window.setTimeout(function() {
                location.href = SITE_URL + "member/view/member_id/"+member_id;
                }, 3000);
           }
        });
        } else {
            $("#send_email_error").show();
        }
        
    
    });

    $(".email_frnd").click(function() {
        var imag_src = $(this).attr('image_src');
        var status = $(this).attr('status');
        var property_price = $(this).attr('property_price');
        var property_name = $(this).attr('property_name');
        var property_id = $(this).attr('property_id');
        var ref_name = $(this).attr('ref_no') + property_id;
        var property_type = $(this).attr('property_type');
        $("#unique_all").val(property_type);
        if (property_type) {
            $("#col-lg-12").hide();

            var chkArray = [];
            $(".chek_all:checked").each(function() {
                chkArray.push($(this).val());
            });
            var selected;
            selected = chkArray.join(',');
            $("#property_all_id").val(selected);

        }


        $("#show_price").html(property_price);
        $("#status").html(status);
        $("#property_name").html(property_name);
        $("#prp_image").attr('src', imag_src);

        $("#ref_name").html(ref_name);
        $("#send_frnd_email").attr('property_id', property_id);
        if (property_type != 'all') {
            $("#myModal_client").modal('show');
            
        } else {
            if (chkArray.length != 0) {
                $("#myModal_client").modal('show');
				$("#send_email_error").hide();
            } else {
                $("#send_email_error").show();
            }

        }

    });

    $("#send_frnd_email").click(function() {
        //alert('in');
        var frnd_name = $("#frnd_name").val();
        var frnd_email = $("#frnd_email").val();
        var your_name = $("#your_name").val();
        var your_email = $("#your_email").val();
        var frnd_tel_no = $("#frnd_tel_no").val();
        var textarea_note = $("#textarea_note").val();
        var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        var property_id = $(this).attr('property_id');
var member_id = $("#current_member_id").val();
        var unique_all = $("#unique_all").val();
        var property_all_id = $("#property_all_id").val();


        $("#error_frnd_name").hide();
        $("#error_frnd_email").hide();
        $("#error_valid_email").hide();
        $("#error_your_name").hide();
        $("#error_your_email").hide();
        $("#frnd_name").removeAttr('style');
        $("#frnd_email").removeAttr('style');
        $("#your_name").removeAttr('style');
        $("#your_email").removeAttr('style');


        if (frnd_name == '') {
            $("#error_frnd_name").show();
            $("#frnd_name").css('border-color', 'red');
            return false;
        } else if (frnd_email == '') {
            $("#error_frnd_email").show();
            $("#frnd_email").css('border-color', 'red');
            return false;
        } else if (frnd_email != '' && regex.test(frnd_email) == false) {
            $("#error_valid_email").show();
            $("#frnd_email").css('border-color', 'red');
            return false;
        } else if (your_name == '') {
            $("#error_your_name").show();
            $("#your_name").css('border-color', 'red');
            return false;
        } else if (your_email == '') {
            $("#error_your_email").show();
            $("#your_email").css('border-color', 'red');
            return false;
        } else if (your_email != '' && regex.test(your_email) == false) {
            $("#error_valid_email").show();
            $("#your_email").css('border-color', 'red');
            return false;
        }

        var postdata = {};
        var obj = $(this);
        postdata['frnd_name'] = frnd_name;
        postdata['frnd_email'] = frnd_email;
        postdata['your_name'] = your_name;
        postdata['your_email'] = your_email;
        postdata['frnd_tel_no'] = frnd_tel_no;
        postdata['textarea_note'] = textarea_note;
        postdata['property_id'] = property_id;
        postdata['unique_all'] = unique_all;
        postdata['property_all_id'] = property_all_id;
        //alert(postdata);
        jQuery.post(BASE_PATH + '/member/sendfriendmail', postdata, function(result) {
            $("#success_frnd_email").show();
            $("#success_frnd_email").html(result);
            window.setTimeout(function() {
                location.href = SITE_URL + "member/form/member_id/"+member_id;
                }, 3000);
        });

    });
    
});
	 
         